package com.hengpeng.itfinbase.persist;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.hengpeng.common.persist.entity.AuditedEntity;
import com.hengpeng.common.web.annotation.HtmlInput;
import com.hengpeng.common.web.annotation.HtmlInputType;
import com.hengpeng.itfinbase.CacheType;
import com.hengpeng.itfinbase.idAssign.AbstractAssign18IdEntity;

/**
 * <pre>
 * 系统角色
 * </pre>
 * @author linriqing
 * @version 1.0, 2010-7-19
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = CacheType.SECOND_CACHE_DEFAULT)
public class AppRole extends AbstractAssign18IdEntity implements AuditedEntity
{
	private static final long serialVersionUID = 1375284442850617084L;

	@Column(length = 50)
	@HtmlInput(label = "角色描述", maxLength = 50, type = HtmlInputType.TEXTAREA, index = 2, nullable = true)
	private String description;

	@Column(length = 20, unique = true)
	@HtmlInput(label = "角色名称", maxLength = 20, type = HtmlInputType.TEXT, index = 1, nullable = false)
	private String name;

	@ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
	@JoinTable(name = "AppRolePermission", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "permission_id") })
	private Set<PermissionPo> permission;

	@ManyToMany(fetch = FetchType.EAGER, mappedBy = "roles")
	private Set<AppUser> users;

	public String getDescription()
	{
		return description;
	}

	public String getName()
	{
		return this.name;
	}

	public Set<PermissionPo> getPermission()
	{
		return this.permission;
	}

	public Set<AppUser> getUsers()
	{
		return users;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public void setPermission(Set<PermissionPo> permission)
	{
		this.permission = permission;
	}

	public void setUsers(Set<AppUser> users)
	{
		this.users = users;
	}

}